package Exceptions;

import java.util.Scanner;

/**
 * @author yangwenqi
 * @decs TODO
 * @date 2025/4/27
 */
public class Login {
    private String id;
    private String password;
    public Login() {
    }
    public Login(String id, String password) {
        this.id = id;
        this.password = password;
    }
    /**
     * 获取
     * @return id
     */
    public String getId() {
        return id;
    }
    /**
     * 设置
     * @param id
     */
    public void setId(String id) {
        if(id.equals("")){
            throw new LoginException("id不能为空");
        }
        this.id = id;
    }
    /**
     * 获取
     * @return password
     */
    public String getPassword() {
        return password;
    }
    /**
     * 设置
     * @param password
     */
    public void setPassword(String password) {
        if(password.equals("")){
            throw new LoginException("密码不能为空");
        }
        this.password = password;
    }
    public String toString() {
        return "LoginException{id = " + id + ", password = " + password + "}";
    }
    public static void main(String[] args) {
        Login login = new Login("111","aaa");
        Scanner sc = new Scanner(System.in);
        try {
            String id1 = login.getId();
            String password1 = login.getPassword();
            System.out.println("请输入用户名：");
            login.setId(sc.nextLine());
            System.out.println("请输入密码：");
            login.setPassword(sc.nextLine());
            login.match(id1,password1);
            System.out.println("登陆成功");
        } catch (LoginException e) {
            e.printStackTrace();
        }finally {
            System.out.println(login.getId());
            System.out.println(login.getPassword());
        }
    }
    public  void match(String id, String password)throws LoginException {
        if(!(id.equals(getId())&&password.equals(getPassword()))){
            throw new LoginException("用户名与密码不匹配");
        }
    }
}
